﻿#ifndef TCP_SOCKET_H
#define TCP_SOCKET_H
#pragma execution_character_set("utf-8")
#include <QTcpSocket>
#include <QDataStream>
#include <QDebug>
#include <QJsonObject>
#include <QJsonDocument>
#include <QTimer>
#include <QDateTime>
#include <enum_type.h>
class tcp_socket:public QTcpSocket
{
  Q_OBJECT
public:
    tcp_socket(QString ip,int port);
    ~tcp_socket();
    QString id;
    void analyse_data();                             //对原始数据进行分析：拆包
    QDateTime Lastconnecttime;
    QTimer clock;                                    //定时检测是否断开
private slots:
     void receive();
     void connect_server();                          //连接服务器
     void isdisconnect();                            //检测是否断开连接
     void send_messagefromslot(QString id,QString type,QString data,tcp_socket *t_socket,emit_type e_type,QString sockettype);
signals:
    void send_ReplyData(QString id,QString type,QString data);  //转发信息给处理模块
private:
   QByteArray json_pack(QString id,QString type,QString data); //json封装
   QStringList json_analyse(QByteArray data);                  //json解析
   void process_data(QByteArray data);                         //处理数据
   void send_data(QByteArray data);                  //发送数据
   QString ip="127.0.0.1";
   int port=60000;
     qint32 feature=19960108;                        //特征值
     QByteArray receive_data;                        //接受的信息

};

#endif // TCP_SOCKET_H

